package com.lori.netshop.controller;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.druid.support.json.JSONUtils;
import com.fasterxml.jackson.core.JsonEncoding;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.lori.netshop.pojo.CatResult;
import com.lori.netshop.service.ItemCatService;

@Controller
public class ItemCatController {
	@Autowired
	private ItemCatService itemCatServiceimp;
	@RequestMapping(value="/itemcat/all",produces=MediaType.APPLICATION_JSON_VALUE + ";charset=utf-8")
	@ResponseBody
	public String getCat(String callback) throws Exception{
		CatResult catresult = itemCatServiceimp.getCatresult();
		//String jsonString = JSONUtils.toJSONString(catresult);
		ObjectMapper objectMapper = new ObjectMapper();
		String json = objectMapper.writeValueAsString(catresult);
		json = callback +"("+json+")";
		return json;
	}
}
